package com.liusy.serachengine;

import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import org.apache.log4j.Logger;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.Field.Store;
import org.apache.lucene.document.StringField;
import org.apache.lucene.document.TextField;


/**
 * 
 * Map索引转换模型抽像类，包括搜索任务
 * 
 * @author liusy 2013-03-25
 *
 */
public class ListMapConvertModel extends AbstractConvertModel {

	private List<Map> list = null;
	
	private static Logger log = Logger.getLogger(FileConvertModel.class);
	
	
	public ListMapConvertModel(List<Map> list)
	{
		this.list = list;
	}
	
	
	/**
	 * Map类型处理
	 * 
	 * @param 
	 * @return
	 */
	@Override
	public Document ObjectConvertDoc(Object obj) {
			Map<String,Object> map = (Map<String,Object>) obj; 
			Document doc = new Document();
			try {
				String totalcontent="";
				for (Entry<String,Object> entry : map.entrySet()) {
					totalcontent +=  entry.getValue().toString(); 
					doc.add(new StringField(entry.getKey(), entry.getValue().toString(), Field.Store.YES));
				}
				doc.add(new TextField("totalcontent", totalcontent, Store.YES));
			
			} catch (Exception e) {
				log.info(e.getMessage());
				log.info("在创建List<Map>索引时出错，该数据被忽略，未创建！");
				return null;
			} finally {

			}
			return doc;
	}


	@Override
	public Object getCreateIndexTask() {
		return list;
	}
	
	

}
